﻿using System;
using System.Collections.Generic;
using System.Data;
using nkstdgia.common.ThamDinhGia.BusinessObjects;

namespace nkstdgia.common.ThamDinhGia.DataAccess
{
    public class THUA_DATDA
    {
        #region ***** Init Methods *****

        public THUA_DATDA()
        {
        }

        #endregion ***** Init Methods *****

        #region ***** Get Methods *****

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public THUA_DAT Populate(IDataReader myReader)
        {
            THUA_DAT obj = new THUA_DAT();
            obj.MA_HO_SO = (Int64)myReader["MA_HO_SO"];
            obj.SO_THUA_DAT = myReader["SO_THUA_DAT"] != DBNull.Value ? (string)myReader["SO_THUA_DAT"] : "";
            obj.TO_BAN_DO = myReader["TO_BAN_DO"] != DBNull.Value ? (string)myReader["TO_BAN_DO"] : "";
            obj.CHIEU_DAI = myReader["CHIEU_DAI"] != DBNull.Value ? (double)myReader["CHIEU_DAI"] : 0.0;
            obj.CHIEU_RONG = myReader["CHIEU_RONG"] != DBNull.Value ? (double)myReader["CHIEU_RONG"] : 0.0;
            obj.TONG_DIEN_TICH = myReader["TONG_DIEN_TICH"] != DBNull.Value ? (double)myReader["TONG_DIEN_TICH"] : 0.0;
            obj.DIEN_TICH_CONG_NHAN = myReader["DIEN_TICH_CONG_NHAN"] != DBNull.Value ? (double)myReader["DIEN_TICH_CONG_NHAN"] : 0.0;
            obj.DIEN_TICH_KHONG_CONG_NHAN = myReader["DIEN_TICH_KHONG_CONG_NHAN"] != DBNull.Value ? (double)myReader["DIEN_TICH_KHONG_CONG_NHAN"] : 0.0;
            obj.DIEN_TICH_SU_DUNG_CHUNG = myReader["DIEN_TICH_SU_DUNG_CHUNG"] != DBNull.Value ? (double)myReader["DIEN_TICH_SU_DUNG_CHUNG"] : 0.0;
            obj.LOAI_HINH_DANG_THUA_DAT = (Int64)myReader["LOAI_HINH_DANG_THUA_DAT"];
            obj.HINH_DANG_THUA_DAT = myReader["HINH_DANG_THUA_DAT"] != DBNull.Value ? (string)myReader["HINH_DANG_THUA_DAT"] : "";
            obj.LOAI_DUONG_PHO = (Int64)myReader["LOAI_DUONG_PHO"];
            obj.LO_GIOI = myReader["LO_GIOI"] != DBNull.Value ? (double)myReader["LO_GIOI"] : 0.0;
            obj.SO_MAT_TIEN = myReader["SO_MAT_TIEN"] != DBNull.Value ? (string)myReader["SO_MAT_TIEN"] : "";
            obj.LOAI_LAN_DUONG = (Int64)myReader["LOAI_LAN_DUONG"];
            obj.NOI_DUNG_LAN_DUONG = myReader["NOI_DUNG_LAN_DUONG"] != DBNull.Value ? (string)myReader["NOI_DUNG_LAN_DUONG"] : "";
            obj.LOAI_HEM = (Int64)myReader["LOAI_HEM"];
            return obj;
        }

        /// <summary>
        /// Get THUA_DAT by ma_ho_so
        /// </summary>
        /// <param name="ma_ho_so">MA_HO_SO</param>
        /// <returns>THUA_DAT</returns>
        public THUA_DAT GetByMA_HO_SO(Int64 ma_ho_so)
        {
            using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THUA_DAT_GetByMA_HO_SO", Data.CreateParameter("MA_HO_SO", ma_ho_so)))
            {
                if (reader.Read())
                {
                    return Populate(reader);
                }
                return null;
            }
        }

        /// <summary>
        /// Get all of THUA_DAT
        /// </summary>
        /// <returns>List<<THUA_DAT>></returns>
        public List<THUA_DAT> GetList()
        {
            using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THUA_DAT_Get"))
            {
                List<THUA_DAT> list = new List<THUA_DAT>();
                while (reader.Read())
                {
                    list.Add(Populate(reader));
                }
                return list;
            }
        }

        /// <summary>
        /// Get DataSet of THUA_DAT
        /// </summary>
        /// <returns>DataSet</returns>
        public DataSet GetDataSet()
        {
            return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THUA_DAT_Get");
        }

        /// <summary>
        /// Get all of THUA_DAT paged
        /// </summary>
        /// <param name="recperpage">record per page</param>
        /// <param name="pageindex">page index</param>
        /// <returns>List<<THUA_DAT>></returns>
        public List<THUA_DAT> GetListPaged(int recperpage, int pageindex)
        {
            using (IDataReader reader = SqlHelper.ExecuteReader(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THUA_DAT_GetPaged"
                            , Data.CreateParameter("recperpage", recperpage)
                            , Data.CreateParameter("pageindex", pageindex)))
            {
                List<THUA_DAT> list = new List<THUA_DAT>();
                while (reader.Read())
                {
                    list.Add(Populate(reader));
                }
                return list;
            }
        }

        /// <summary>
        /// Get DataSet of THUA_DAT paged
        /// </summary>
        /// <param name="recperpage">record per page</param>
        /// <param name="pageindex">page index</param>
        /// <returns>DataSet</returns>
        public DataSet GetDataSetPaged(int recperpage, int pageindex)
        {
            return SqlHelper.ExecuteDataSet(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THUA_DAT_GetPaged"
                            , Data.CreateParameter("recperpage", recperpage)
                            , Data.CreateParameter("pageindex", pageindex));
        }

        #endregion ***** Get Methods *****

        #region ***** Add Update Delete Methods *****

        /// <summary>
        /// Add a new THUA_DAT within THUA_DAT database table
        /// </summary>
        /// <param name="obj">THUA_DAT</param>
        /// <returns>key of table</returns>
        public long Add(THUA_DAT obj)
        {
            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THUA_DAT_Add"
                            , Data.CreateParameter("MA_HO_SO", obj.MA_HO_SO)
                            , Data.CreateParameter("SO_THUA_DAT", obj.SO_THUA_DAT)
                            , Data.CreateParameter("TO_BAN_DO", obj.TO_BAN_DO)
                            , Data.CreateParameter("CHIEU_DAI", obj.CHIEU_DAI)
                            , Data.CreateParameter("CHIEU_RONG", obj.CHIEU_RONG)
                            , Data.CreateParameter("TONG_DIEN_TICH", obj.TONG_DIEN_TICH)
                            , Data.CreateParameter("DIEN_TICH_CONG_NHAN", obj.DIEN_TICH_CONG_NHAN)
                            , Data.CreateParameter("DIEN_TICH_KHONG_CONG_NHAN", obj.DIEN_TICH_KHONG_CONG_NHAN)
                            , Data.CreateParameter("DIEN_TICH_SU_DUNG_CHUNG", obj.DIEN_TICH_SU_DUNG_CHUNG)
                            , Data.CreateParameter("LOAI_HINH_DANG_THUA_DAT", obj.LOAI_HINH_DANG_THUA_DAT)
                            , Data.CreateParameter("HINH_DANG_THUA_DAT", obj.HINH_DANG_THUA_DAT)
                            , Data.CreateParameter("LOAI_DUONG_PHO", obj.LOAI_DUONG_PHO)
                            , Data.CreateParameter("LO_GIOI", obj.LO_GIOI)
                            , Data.CreateParameter("SO_MAT_TIEN", obj.SO_MAT_TIEN)
                            , Data.CreateParameter("LOAI_LAN_DUONG", obj.LOAI_LAN_DUONG)
                            , Data.CreateParameter("NOI_DUNG_LAN_DUONG", obj.NOI_DUNG_LAN_DUONG)
                            , Data.CreateParameter("LOAI_HEM", obj.LOAI_HEM)
            );
            return obj.MA_HO_SO;
        }

        /// <summary>
        /// updates the specified THUA_DAT
        /// </summary>
        /// <param name="obj">THUA_DAT</param>
        /// <returns></returns>
        public void Update(THUA_DAT obj)
        {
            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THUA_DAT_Update"
                            , Data.CreateParameter("MA_HO_SO", obj.MA_HO_SO)
                            , Data.CreateParameter("SO_THUA_DAT", obj.SO_THUA_DAT)
                            , Data.CreateParameter("TO_BAN_DO", obj.TO_BAN_DO)
                            , Data.CreateParameter("CHIEU_DAI", obj.CHIEU_DAI)
                            , Data.CreateParameter("CHIEU_RONG", obj.CHIEU_RONG)
                            , Data.CreateParameter("TONG_DIEN_TICH", obj.TONG_DIEN_TICH)
                            , Data.CreateParameter("DIEN_TICH_CONG_NHAN", obj.DIEN_TICH_CONG_NHAN)
                            , Data.CreateParameter("DIEN_TICH_KHONG_CONG_NHAN", obj.DIEN_TICH_KHONG_CONG_NHAN)
                            , Data.CreateParameter("DIEN_TICH_SU_DUNG_CHUNG", obj.DIEN_TICH_SU_DUNG_CHUNG)
                            , Data.CreateParameter("LOAI_HINH_DANG_THUA_DAT", obj.LOAI_HINH_DANG_THUA_DAT)
                            , Data.CreateParameter("HINH_DANG_THUA_DAT", obj.HINH_DANG_THUA_DAT)
                            , Data.CreateParameter("LOAI_DUONG_PHO", obj.LOAI_DUONG_PHO)
                            , Data.CreateParameter("LO_GIOI", obj.LO_GIOI)
                            , Data.CreateParameter("SO_MAT_TIEN", obj.SO_MAT_TIEN)
                            , Data.CreateParameter("LOAI_LAN_DUONG", obj.LOAI_LAN_DUONG)
                            , Data.CreateParameter("NOI_DUNG_LAN_DUONG", obj.NOI_DUNG_LAN_DUONG)
                            , Data.CreateParameter("LOAI_HEM", obj.LOAI_HEM)
            );
        }

        /// <summary>
        /// Delete the specified THUA_DAT
        /// </summary>
        /// <param name="ma_ho_so">MA_HO_SO</param>
        /// <returns></returns>
        public void Delete(Int64 ma_ho_so)
        {
            SqlHelper.ExecuteNonQuery(Data.ConnectionString, CommandType.StoredProcedure, "sproc_THUA_DAT_Delete", Data.CreateParameter("MA_HO_SO", ma_ho_so));
        }

        #endregion ***** Add Update Delete Methods *****
    }
}